package org.zsl.controller.doc;

import com.alibaba.fastjson.JSON;
import org.springframework.web.bind.annotation.*;
import org.zsl.model.Employee;
import org.zsl.service.EmployeeService;


/**
 * restful 风格
 */
@RestController
@RequestMapping("/doc2")
@CrossOrigin
public class BasicController2 {

    private EmployeeService service = new EmployeeService();


    @GetMapping("/list")
    public String list() {
        return JSON.toJSONString(service.getAll());
    }

    @GetMapping({"/query/{id}"})
    public String query(@PathVariable("id") int id) {
        System.out.println(id);
        return JSON.toJSONString(service.getEmployeeById(id));
    }

    @DeleteMapping({"/del/{id}"})
    public String del(@PathVariable("id") int id) {

        return JSON.toJSONString(service.delelteEmployee(id));
    }

    @PostMapping("/add")
    public String add(Employee employee) {

        System.out.println(employee.getName());

        return JSON.toJSONString(service.add(employee));
    }

    @PutMapping("/update")
    public String update(Employee employee){

        System.out.println(employee.getName());

       return JSON.toJSONString(service.update(employee));

    }


}
